package 代码随想录.贪心;

public class a376摆动序列 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 17, 5, 10, 13, 15, 10, 5, 16, 8};
        System.out.println(solution.wiggleMaxLength(nums));
    }

    static class Solution {
        public int wiggleMaxLength(int[] nums) {
            if (nums.length == 1) return 1;
            // if (nums.length == 2) return nums[0] == nums[1] ? 1 : 2; // 可选
            int predif = 0;
            int curdif = 0;
            int res = 1; // 最后一个一定会有
            for (int i = 0; i < nums.length - 1; i++) {
                curdif = nums[i + 1] - nums[i];
                if ((predif <= 0 && curdif > 0) || (predif >= 0 && curdif < 0)) {
                    res++;
                    predif = curdif;
                }
            }
            return res;
        }
    }
}
